//
//  UserViewController.m
//  demo
//
//  Created by dllo on 15/7/11.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "UserViewController.h"
#import "SDImageCache.h"
@interface UserViewController () <UIAlertViewDelegate>
@property (nonatomic, retain) NSString *str;
@end

@implementation UserViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"更多";
   
    self.view.backgroundColor = [UIColor clearColor];
    self.arr = [@[@"我的收藏",@"清除缓存",@"关于我们"]mutableCopy];
    
    self.backImg = [[UIImageView alloc]initWithFrame:self.view.bounds];
    self.backImg.image = [UIImage imageNamed:@"user back.jpg"];
    [self.view addSubview:self.backImg];
    [_backImg release];
    [self createButton];
}

-(void)createButton
{
    self.collectionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.collectionBtn.frame = CGRectMake(self.view.frame.size.width / 4, 120, self.view.frame.size.width / 2, 30);
    self.collectionBtn.backgroundColor = [UIColor clearColor];
    [self.collectionBtn setTitle:@"我的收藏" forState:UIControlStateNormal];
    self.collectionBtn.layer.cornerRadius = 13;
    self.collectionBtn.layer.masksToBounds = YES;
    self.collectionBtn.layer.borderWidth = 1.0;
    self.collectionBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.collectionBtn addTarget:self action:@selector(collectionBtnTouch) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.collectionBtn];

    
    NSInteger size = [[SDImageCache sharedImageCache] getSize];
    self.str = [NSString stringWithFormat:@"清除缓存   %ld MB", size / (1024 * 1024)];
    self.clearCacheBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.clearCacheBtn.frame = CGRectMake(self.view.frame.size.width / 4, 180, self.view.frame.size.width / 2, 30);
    self.clearCacheBtn.backgroundColor = [UIColor clearColor];
    [self.clearCacheBtn setTitle:self.str forState:UIControlStateNormal];
    self.clearCacheBtn.layer.cornerRadius = 13;
    self.clearCacheBtn.layer.masksToBounds = YES;
    self.clearCacheBtn.layer.borderWidth = 1.0;
    self.clearCacheBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.clearCacheBtn addTarget:self action:@selector(clearCacheBtnTouch) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.clearCacheBtn];

    self.usBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.usBtn.frame = CGRectMake(self.view.frame.size.width / 4, 240, self.view.frame.size.width / 2, 30);
    self.usBtn.backgroundColor = [UIColor clearColor];
    [self.usBtn setTitle:@"关于我们" forState:UIControlStateNormal];
    self.usBtn.layer.cornerRadius = 13;
    self.usBtn.layer.masksToBounds = YES;
    self.usBtn.layer.borderWidth = 1.0;
    self.usBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.usBtn addTarget:self action:@selector(usBtnTouch) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.usBtn];
}

-(void)collectionBtnTouch
{
    collectionViewController *collectionVC = [[collectionViewController alloc]init];
    [self.navigationController pushViewController:collectionVC animated:YES];
}

-(void)clearCacheBtnTouch
{
    UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您确定要清除所有缓存么?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [al show];
    [al release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (1 == buttonIndex) {
        //NSInteger size = [[SDImageCache sharedImageCache] getSize];
        [[SDImageCache sharedImageCache] clearDisk];
        self.str = [NSString stringWithFormat:@"清除缓存   0 MB"];
        [self.clearCacheBtn setTitle:self.str forState:UIControlStateNormal];
        [self.userTableView reloadData];
    }
}
-(void)usBtnTouch
{

    usViewController *usVC = [[usViewController alloc]init];
    [self.navigationController pushViewController:usVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
